var jsdom = require('jsdom');
module.exports = {
	scrape: function (chunk) {
		var datas = new Array();
		var window = jsdom.env({
			html: chunk,
			done: function(errors, window) {
				var $ = require('jquery').create(window);
				var apps = $('.info'); //div for app
				var tableMe;
				for(var i = 0; i < apps.length; i++) {
					var appwindow = jsdom.env({
						html: apps[i],
						done: function(err, dub) {
							tableMe = new Array();
							var dolla = require('jquery').create(dub);
							var info = dolla('.titleline');

							tableMe.url = 
						}
					});
					

					if($(apps[i]).children(".price").text() == "Free") {
						tableMe.url = $(apps[i]).children(".title").children("a").attr("href");
						tableMe.title = $(apps[i]).children(".title").children("a").text();
						tableMe.version = $(apps[i]).children(".title").children(".version").text();
						tableMe.author = $(apps[i]).children(".submitted").children("a").text();
						tableMe.date = $(apps[i]).children(".submitted").text();
						tableMe.date = tableMe.date.substring(tableMe.date.indexOf("Updated") + 7);
						tableMe.downloads = $(apps[i]).children(".clear-block").children(".downloads").text();
						
						console.log("INFO for " + tableMe.title);
						console.log("\t URL: " + tableMe.url);
						console.log("\t VERSION: " + tableMe.version);
						console.log("\t AUTHOR: " + tableMe.author);
						console.log("\t DATE: " + tableMe.date);
						console.log("\t DOWNLOADS: " + tableMe.downloads);
						console.log("------------------------------------");

						datas.push(tableMe);
					}		
				}
			}
		});
		return datas;
	}
}